

$(document).ready(function() { 
    $("#selectAll").click(function(){
        if($("#selectAll").attr("checked") == false){
            $(".selectStudents").attr("checked",false)
        }else{
            $(".selectStudents").attr("checked",true)
        }
    })


    $(".selectStudents").click(function(){
        flag = true;
        $(".selectStudents").each(function(i,n){
            if($(this).attr("checked") == false){
                flag = false
            }
        })
        if(flag){
            $("#selectAll").attr("checked",true)
        }else{
            $("#selectAll").attr("checked",false)
        }
    })

    $("#submitStudents").click(function(){
        if($.trim($("#classes").val()) != ""){
            $("#submitStudents").attr("disabled",true)
            $(".selectStudents").each(function(i,n){
                if($(this).attr("checked") == true){
                    $("#selectStudentList").val($("#selectStudentList").val()+$(this).val()+",")
                }
            }) 
            $.post("/cloud/classesAjax/removeStudentsToClasses", {time:new Date().getTime(),selectStudent:$('#selectStudentList').val(),newClassesid:$('#classes').val()}, function(data) {
                 if( data.success == true ){
                    $('#removeClassesMessage').html(data.message); 
                    window.location.reload()
                }else{
                    $('#removeClassesMessage').html(data.message);
                }
                $("#submitStudents").attr("disabled",false)
            }, 'json');
        }else{
            alert("请选择要移动的班级");
        }
    })
});